<template>
	<el-container>
		<el-header class="header-tabs">
			<el-tabs type="card" v-model="params.type" @tab-change="tabChange">
<!--				<el-tab-pane label="全部" name=""></el-tab-pane>-->
				<el-tab-pane label="收入" :name="1"></el-tab-pane>
				<el-tab-pane label="支出" :name="2"></el-tab-pane>
			</el-tabs>
		</el-header>
		<el-header>
			<div class="left-panel">
				<!--导出-->
				<sc-export-button :auth="'finance.recordExport'" :apiObj="apiObj" :search="search"></sc-export-button>
				<div class="finish">
					<div class="finishNum" v-if="params.type == 1">总收入:
						<div class="text">{{ total_stock.collect }}</div>
					</div>
					<div class="finishNum" v-if="params.type == 2">总支出:
						<div class="text">{{ total_stock.pay }}</div>
					</div>
				</div>
			</div>
			<div class="right-panel">
				<div class="right-panel-search">
					<el-date-picker v-model="search.business_date" :value-format="'YYYY-MM-DD'" type="daterange" range-separator="至" start-placeholder="开始日期"
									end-placeholder="结束日期"/>
<!--					<el-select v-model="search.customer_id" filterable clearable placeholder="请选择客户" v-if="params.type == 1">-->
<!--						<el-option v-for="item in clientList" :key="item.id" :label="item.customer_name" :value="item.id"/>-->
<!--					</el-select>-->
<!--					<el-select v-model="search.supplier_id" placeholder="请选择供应商" filterable clearable v-if="params.type == 2">-->
<!--						<el-option v-for="item in applyList" :key="item.apply_id" :label="item.apply_name" :value="item.apply_id"></el-option>-->
<!--					</el-select>-->
					<el-input v-model="search.pay_target" :placeholder="params.type == 1 ?'请输入收款单位':'请输入付款单位'" clearable @keyup.enter="upsearch"></el-input>
					<!-- <el-input v-model="search.open_bank" placeholder="请输入开户行" clearable @keyup.enter="upsearch"></el-input> -->
					<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
					<el-button type="primary" icon="el-icon-refresh" @click="refresh"></el-button>
				</div>
			</div>
		</el-header>
		<el-main class="nopadding">
			<scTable ref="table" row-key="id" :apiObj="apiObj" :params="params" @selection-change="selectionChange" stripe remoteSort remoteFilter border @setExtend="setExtend">
				<el-table-column type="selection" width="50" reserve-selection align="center"></el-table-column>
				<el-table-column type="index" label="序号" fixed align="center" width="50"></el-table-column>
<!--				<el-table-column label="收支类型" prop="type" align="center">-->
<!--					<template #default="scope">-->
<!--						<span v-if="scope.row.type == 1">收入</span>-->
<!--						<span v-if="scope.row.type == 2">支出</span>-->
<!--					</template>-->
<!--				</el-table-column>-->
				<el-table-column label="单据编号" prop="collect_pay_code" align="center"></el-table-column>
				<el-table-column label="单据日期" prop="business_date" align="center"></el-table-column>
				<el-table-column label="收款单位" prop="pay_target" align="center"  v-if="params.type == 1"></el-table-column>
        <el-table-column label="收款类型" prop="collect_pay_project" align="center"  v-if="params.type == 1"></el-table-column>
				<el-table-column label="付款单位" prop="pay_target" align="center" v-if="params.type == 2"></el-table-column>
        <el-table-column label="付款类型" prop="collect_pay_project" align="center"  v-if="params.type == 2"></el-table-column>
				<el-table-column label="状态" prop="is_cancel" align="center">
					<template #default="scope">
						<el-tag :type="scope.row.is_cancel == 1 ? 'danger' :  'success'">
							{{ scope.row.is_cancel == 1 ? ' 已作废' : '正常' }}
						</el-tag>
					</template>
				</el-table-column>
				<!-- <el-table-column label="联系人" prop="customer.contacts" align="center"></el-table-column>
				<el-table-column label="联系电话" prop="customer.mobile" align="center"></el-table-column> -->
				<el-table-column label="结算账户" prop="settlement.account" align="center"></el-table-column>
				<el-table-column label="收入" prop="collect" align="center" v-if="params.type == 1"></el-table-column>
				<el-table-column label="支出" prop="pay" align="center" v-if="params.type == 2"></el-table-column>
			</scTable>
		</el-main>
	</el-container>
</template>

<script>

export default {
	name: '客户列表',
	data() {
		return {
			apiObj: this.$API.finance.recordlist,
			selection: [],
			search: {
				customer_id: null,
				supplier_id: null,
				business_date:null,
				pay_target:null
			},
			clientList: [],
			applyList: [],
			total_stock: {},
			params:{
				type:1,
			},
		}
	},
	mounted() {
		this.getClient();
		this.getApply()
	},
	methods: {
		/**tab搜索*/
		tabChange() {
			this.upsearch()
		},
		setExtend(data) {
			this.total_stock = data
		},
		//搜索
		upsearch() {
			this.$refs.table.upData(this.search)
		},
		refresh() {
			for (const key in this.search) {
				this.search[key] = null;
			}
			this.$refs.table.upData(this.search)
		},
		// 客户
		async getClient() {
			var res = await this.$API.client.client.all.get();
			this.clientList = res.data;
		},
		// 供应商
		async getApply() {
			var res = await this.$API.apply.apply.all.get();
			this.applyList = res.data;
		},
	}
}
</script>

<style></style>
